<?php

namespace App;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
    protected $fillable=['title','content','published_at'];
    protected $dates=['published_at'];//把时间转化为carbon对象
    public function setPublishedAtAttribute($date){
        $this->attributes['published_at']=Carbon::createFromFormat('Y-m-d',$date);
    }
    public function scopePublised($query)
    {
        $query->where('published_at','<=',Carbon::now());
    }
//文章属于某一个作者
    public function user()
    {
        return $this->belongsTo('App\user');
    }
}
